package com.property.manage.controller.renovation;

import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.model.renovation.RenovationVo;
import com.property.manage.model.system.SysSet;
import com.property.manage.service.renovation.RenovationService;
import com.property.manage.service.system.SysSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/15
 */
@Api(tags = "装修登记")
@RestController
@RequestMapping("/renovation")
@AllArgsConstructor
@Validated
public class RenovationController {
    @Autowired
    private RenovationService renovationService;

    @Autowired
    private SysSetService sysSetService;
    @ApiOperation("押金状态")
    @GetMapping("/type")
    public List<SysSet> type(){
        return sysSetService.getSysSets(SysSet.DEPOSIT_TYPE);
    }
    @ApiOperation("装修状态")
    @GetMapping("/retype")
    public List<SysSet> retype(){
        return sysSetService.getSysSets(SysSet.RENOVATION_TYPE);
    }

    @ApiOperation("列表")
    @GetMapping("/page")
    public CustomPage<RenovationVo> getPage(@ApiParam("当前页码") @RequestParam("pageNo") @NotNull(message = "请输入当前页码") Long pageNo,
                                            @ApiParam("每页条数") @RequestParam("pageSize") @NotNull(message = "请输入每页条数") Long pageSize,
                                            @ApiParam("小区id") @RequestParam(value = "villageId", required = false) Integer villageId,
                                            @ApiParam("楼栋") @RequestParam(value = "building", required = false) Integer building,
                                            @ApiParam("单元") @RequestParam(value = "unit", required = false) Integer unit,
                                            @ApiParam("房号") @RequestParam(value = "roomNumber", required = false) String roomNumber,
                                            @ApiParam("开始时间") @RequestParam(value = "startTime", required = false) String startTime,
                                            @ApiParam("结束时间") @RequestParam(value = "endTime", required = false) String endTime){
        return renovationService.page(pageNo,pageSize,villageId,building, unit, roomNumber, startTime,endTime);
    }


    @ApiOperation("添加")
    @PostMapping("/add")
    public void add(@ApiIgnore @RequestParam("userId") @NotNull(message = "您尚未登录") Integer userId,
                    @ApiParam("楼栋id")@RequestParam(value = "buildingId")@NotNull(message = "楼栋id不能为空") Integer buildingId,
                    @ApiParam("业主名称")@RequestParam(value = "name", required = false) String name,
                    @ApiParam("手机号码")@RequestParam(value = "phone", required = false) String phone,
                    @ApiParam("押金金额")@RequestParam(value = "money", required = false)  BigDecimal money,
                    @ApiParam("装修开始时间")@RequestParam(value = "startTime", required = false) LocalDate startTime,
                    @ApiParam("装修结束时间")@RequestParam(value = "endTime", required = false) LocalDate endTime,
                    @ApiParam("装修状态 1 未装修 装修中 已完成")@RequestParam(value = "decorationStatus")@NotNull(message = "装修状态不能为空") Integer decorationStatus

    ){
       renovationService.add(money,startTime,endTime,name,phone,buildingId,decorationStatus,userId);
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public void update(@RequestParam(value = "id")@NotNull(message = "id不能为空") Integer id,
                       @ApiParam("楼栋id")@RequestParam(value = "buildingId")@NotNull(message = "楼栋id不能为空") Integer buildingId,
                       @ApiParam("业主名称")@RequestParam(value = "name", required = false) String name,
                       @ApiParam("手机号码")@RequestParam(value = "phone", required = false) String phone,
                       @ApiParam("押金金额")@RequestParam(value = "money", required = false)  BigDecimal money,
                       @ApiParam("装修开始时间")@RequestParam(value = "startTime", required = false) LocalDate startTime,
                       @ApiParam("装修结束时间")@RequestParam(value = "endTime", required = false) LocalDate endTime,
                       @ApiParam("装修状态 1 未装修 装修中 已完成")@RequestParam(value = "decorationStatus")@NotNull(message = "装修状态不能为空") Integer decorationStatus
    ){
      renovationService.update(id,money,startTime,endTime,name,phone,buildingId,decorationStatus);
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public void delete(@ApiParam("id") @RequestParam("id") @NotNull(message = "id为空") Integer id){
        renovationService.delete(id);
    }


}
